/*
 Copyright 2012 Ronald Pablos 

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */
package org.bn.types;

import java.text.SimpleDateFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author Ronald
 */
public class Date {
    static Pattern p = Pattern.compile("(\\d{4})-?(\\d{2})-?(\\d{2})");
    int year, month, day;
    
    public Date(int year, int month, int day) {
        this.year = year;
        this.month = month;
        this.day = day;
    }
    public Date(String theDate) {
        Matcher m = p.matcher(theDate);
        if (!m.matches())
            throw new IllegalArgumentException("Date string is not the format YYYY-MM-DD");
        
        year = Integer.parseInt(m.group(1));
        month = Integer.parseInt(m.group(2));
        day = Integer.parseInt(m.group(3));
    }

    public int getYear() {
        return year;
    }

    public int getMonth() {
        return month;
    }

    public int getDay() {
        return day;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public void setDay(int day) {
        this.day = day;
    }

 

    @Override
    public String toString() {
        return String.format("%1$04d-%2$02d-%3$02d",year,month,day);
        
    }
    
}
